/**
    Copyright (C) 2011  Alexander Vollmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jefb.util.service.impl;

import java.util.Date;

import org.jefb.service.ICommonPersistenceService;
import org.jefb.util.entity.AgentAction;
import org.jefb.util.entity.AgentActionLogEntity;
import org.jefb.util.entity.UserAction;
import org.jefb.util.entity.UserActionEntity;
import org.jefb.util.service.IActionLoggerService;

/**
 * This service logs similar user activities.
 * @author alexej
 *
 */
public class ActionLoggerService implements IActionLoggerService{

	private Config config;
	private ICommonPersistenceService commonPersistenceService;

	public void setConfig(Config config) {
		this.config = config;
	}

	public Config getConfig() {
		return config;
	}

	public void logAgentAction(String agentId, AgentAction agentAction) {
		AgentActionLogEntity agentActionLogEntity = new AgentActionLogEntity();
		agentActionLogEntity.setAgentAction(agentAction);
		agentActionLogEntity.setAgentId(agentId);
		agentActionLogEntity.setCreationTime(new Date());
		commonPersistenceService.persistEntity(agentActionLogEntity);
	}

	/**
	 * Log user action by action type for given user.
	 */
	public void logUserAction(String username, UserAction userAction) {
		UserActionEntity userActionLogEntity = new UserActionEntity();
		userActionLogEntity.setUserAction(userAction);
		userActionLogEntity.setUsername(username);
		userActionLogEntity.setCreationTime(new Date());
		commonPersistenceService.persistEntity(userActionLogEntity);
	}

	public void setCommonPersistenceService(ICommonPersistenceService commonPersistenceService) {
		this.commonPersistenceService = commonPersistenceService;
	}

	public ICommonPersistenceService getCommonPersistenceService() {
		return commonPersistenceService;
	}

}
